class Solution {
public:
    string convert(string s, int numRows) {
        if(numRows == 1) return s;
        string res = "";
        int phase = 2 * numRows - 2;
        int i = 0;
        while(i < s.length())
        {
            res += s[i];
            // cout<<res<<endl;
            i += phase;
        }
        // cout<<"mark"<<endl;
        for(i = 1; i < numRows - 1; i++)
        {
            int j = i;
            while(j < s.length())
            {
                res += s[j];
                // cout<<res<<endl;
                j += phase - 2 * i;
                if(j < s.length())
                {
                    res += s[j];
                    // cout<<res<<endl;
                    j += 2 * i;
                }
                else
                    break;
            }
        }
        // cout<<"mark"<<endl;
        i = numRows - 1;
        while(i < s.length())
        {
            res += s[i];
            i += phase;
        }
        return res;
    }
};
